package com.hd.trans.widgets;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;

import androidx.annotation.Nullable;

import org.jetbrains.annotations.NotNull;

public class EllipsizeEndTextView extends androidx.appcompat.widget.AppCompatTextView {
    public EllipsizeEndTextView(@NotNull Context context) {
        this(context,null);
    }

    public EllipsizeEndTextView(@NotNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, android.R.attr.textViewStyle);
    }

    public EllipsizeEndTextView(@NotNull Context context, @Nullable  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setEllipsize(TextUtils.TruncateAt.END);
        setMaxLines(1);
        setGravity(Gravity.LEFT);
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        if(!TextUtils.isEmpty(text) && text.length() >6){
            text = text.subSequence(0,5) + "...";
        }
        super.setText(text, type);
    }

}
